package org.come.MountShouHu;



import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;
import org.come.Frame.MountShouhuJframe;
import org.come.Frame.ZhuFrame;
import org.come.entity.Goodstable;
import org.come.entity.Mount;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.*;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

public class ShouhuPackGoodsMouslisten implements MouseListener {
    private static ShouhuPackJpanel shouhuPackJpanel;
    private int[] xy;
    private int goodPlace;
    private static RandFJpanel randFJpanel;
    int p=-1;
    public ShouhuPackGoodsMouslisten(int i,ShouhuPackJpanel shouhuPackJpanel, final int[] xy){
        ShouhuPackGoodsMouslisten.shouhuPackJpanel = shouhuPackJpanel;
        this.xy = xy;
        this.goodPlace = i;
    }
    public ShouhuPackGoodsMouslisten(int i,RandFJpanel randFJpanel){
        ShouhuPackGoodsMouslisten.randFJpanel = randFJpanel;
        p=i;

    }
    public ShouhuPackGoodsMouslisten(int i){

        p=i;

    }
    @Override
    public void mouseClicked(MouseEvent e) {
        if (ImageMixDeal.userimg.getRoleShow().getBooth_id() != null) {
            ZhuFrame.getZhuJpanel().addPrompt2("摆摊状态不可以熔炼操作！");
            return;
        }
        if (e.getButton()== MouseEvent.BUTTON1 && e.getClickCount() == 1)
            shouhuPackJpanel.xuanzhong(goodPlace);
        else if (e.getButton()== MouseEvent.BUTTON1 && e.getClickCount() == 2){
            FormsManagement.HideForm(2257);
            RandFJpanel randFJpanel=RandFJframe.getRandFJframe().getRandFJpanel();
            if (MountShouhuJframe.getMountShouhuJframe().getMountShouhuJpanel().s){
                List<Mount>list= UserMessUntil.getMountlsit();
                if (RoleData.getRoleData().getLoginResult().getJiesuo()==null){
                    return;
                }
                final int l= Integer.parseInt(RoleData.getRoleData().getLoginResult().getJiesuo().split("\\|")[MountShouhuJframe.getMountShouhuJframe().getMountShouhuJpanel().l]);
                if (l==-1||l==0)return;
                int k=goodPlace*(shouhuPackJpanel.page==0?1:shouhuPackJpanel.page);
                if (k>=shouhuPackJpanel.getGoodstableList().size())
                    return;
                if (shouhuPackJpanel.getGoodstableList().size()==0)return;
                Goodstable goodstable=shouhuPackJpanel.getGoodstableList().get(k);
                for (int y=0;y<=list.size()-1;y++){
                    if (list.get(y).getMountid()==l){
                        if (list.get(y).getShouhu()!=0){
                            for (int f=0;f<=ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.size()-1;f++){
                                if (ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.get(f).getRgid().intValue()==list.get(y).getShouhu()){
                                    ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.get(f).setStatus(0);
                                    GoodsListFromServerUntil.newgood( ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.get(f));
                                    ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getGoodstableList().add(ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.get(f));
                                    String sendmes2 = Agreement.getAgreement().rolechangeAgreement("up&"+GsonUtil.getGsonUtil().getgson().toJson(ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.get(f)));
                                    SendMessageUntil.toServer(sendmes2);
                                }
                            }
                            ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.removeIf(goodstable1 -> goodstable1.getStatus()==0);
                            ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getGoodstableList().removeIf(goodstable1 -> goodstable1.getStatus()==1);
                        }
                        list.get(y).setShouhu(goodstable.getRgid().intValue());
                        String sendmes = Agreement.getAgreement().changeMountValue(GsonUtil.getGsonUtil().getgson().toJson(list.get(y)));
                        SendMessageUntil.toServer(sendmes);
                        goodstable.setStatus(1);
                        shouhuPackJpanel.Eqment.add(goodstable);
                        shouhuPackJpanel.getGoodstableList().remove(goodstable);
                        shouhuPackJpanel.updata();
                        sendmes = Agreement.getAgreement().rolechangeAgreement("up&"+GsonUtil.getGsonUtil().getgson().toJson(goodstable));
                        SendMessageUntil.toServer(sendmes);
                    }
                }
                GoodsListFromServerUntil.shouhu(goodstable.getRgid().intValue());
                MountShouhuJframe.getMountShouhuJframe().getMountShouhuJpanel().s=false;
                try {
                    MountShouhuJframe.getMountShouhuJframe().getMountShouhuJpanel().shouhuBtn[MountShouhuJframe.getMountShouhuJframe().getMountShouhuJpanel().l].setIcons(CutButtonImage.cuts("inkImg/Client/守护石圆圈带守护石.png"));
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
                MountShouhuJframe.getMountShouhuJframe().getMountShouhuJpanel().l=-1;
            }else {
                if (shouhuPackJpanel.getGoodstableList().size()==0)return;
                if (randFJpanel.getType()==1){
                    shouhuPackJpanel.setXuanzhong1(goodPlace+shouhuPackJpanel.page*12);
                }else  if (randFJpanel.getType()==2){
                    if (shouhuPackJpanel.getIdx()==1){
                        shouhuPackJpanel.setXuanzhong1(goodPlace+shouhuPackJpanel.page*12);
                    }else   if (shouhuPackJpanel.getIdx()==2){
                        shouhuPackJpanel.setXuanzhong2(goodPlace+shouhuPackJpanel.page*12);
                    }
                }
            }

            FormsManagement.HideForm(24);
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        if (ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getGoodstableList().size()==0)return;
        if (p==10){
            int i=ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getXuanzhong1();
            Goodstable goodstable=ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getGoodstableList().get(i);
            if (goodstable!=null){
                ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
            }
        }else if (p==11){
            int i=ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getXuanzhong1();
            Goodstable goodstable=ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getGoodstableList().get(i);
            if (goodstable!=null){
                ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
            }
        }else if (p==12){
            int i=ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getXuanzhong2();
            Goodstable goodstable=ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().getGoodstableList().get(i);
            if (goodstable!=null){
                ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
            }
        }else if (p>=60&&p<=66){
            int l=p-60;
            if (RoleData.getRoleData().getLoginResult().getJiesuo()==null)return;
            int n=Integer.parseInt(RoleData.getRoleData().getLoginResult().getJiesuo().split("\\|")[l]);
            if (n==-1)return;
            List<Mount>list= UserMessUntil.getMountlsit();
            list.forEach(el->{
                if (el.getMountid()==n){
                    ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().Eqment.forEach(p->{
                        if (p.getRgid().intValue()==el.getShouhu())
                            ZhuFrame.getZhuJpanel().creatgoodtext(p);
                    });

                }
            });
        }else {
            shouhuPackJpanel.effect(goodPlace);
            int k=goodPlace+shouhuPackJpanel.page*12;
            if (k>=shouhuPackJpanel.getGoodstableList().size())
                return;

            Goodstable goodstable=shouhuPackJpanel.getGoodstableList().get(k);
            if (goodstable!=null){
                ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
            }
        }

    }

    @Override
    public void mouseExited(MouseEvent e) {
        shouhuPackJpanel.effect(-1);
        FormsManagement.HideForm(24);
    }
}
